#pragma once

#include"Common.h"
#include"ObjectPool.h"
#include"PageMap.h"
//单例模式
class PageCache
{
public:
	static PageCache* GetInstance()
	{
		return _pInst;
	}

	//获取从对象到span的映射
	Span* MapObjToSpan(void* obj);

	//获取一个K页Span
	Span* NewSpan(size_t k);

	// 释放空闲span回到Pagecache，并合并相邻的span
	void ReleaseSpanToPageCache(Span* span);

	std::mutex _pageMtx;//全局锁

private:
	SpanList _spanLists[NPAGES];//页数作桶的映射下标

	//std::unordered_map<PAGE_ID, Span*>_idSpanMap;

	TCMalloc_PageMap1<32 - PAGE_SHIFT>_idSpanMap;//使用基数树

	ObjectPool<Span>_spanPool;
private:
	PageCache()
	{}
	PageCache(const PageCache&) = delete;
	static PageCache* _pInst;

};